home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / dynExpressions.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  10.9 KB  |  413 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. //
  18. //  Alias|Wavefront Script File
  19. //  MODIFY THIS AT YOUR OWN RISK
  20. //
  21. //  ==================== dynExpressions.mel ==========
  22. //
  23. //  SYNOPSIS
  24. //      Manage particle expressions for the Expression Editor.
  25. //
  26. //  CONTENTS
  27. //        (The procs are in the file in the order listed here.)
  28. //
  29. //    Particle Expression Procedures:
  30. //
  31. //    EEisParticle            Is the node a particle?
  32. //    EEisDynExpression        Is the particle expression a dynExpression?
  33. //    EEisValidDynAttr        Is the particle attribute a valid one to show?
  34. //    EEgetParticleExpression Get the p. expression from the particle
  35. //    EEdisplayParticleExpression    Display a particle expression.
  36. //    EEdynExpressionCmd        Print the expression command just issued.
  37. //    EEapplyParticleExpression    Create or edit the particle expression
  38. //    EErestoreParticleExpression    Restore curr particle expression from node.
  39. //  EEparticleListChanged    User selected a particle in the node list.
  40. //    EEonlyLaunchParticleEditor Launch a text editor for a particle expression.
  41. //
  42. //
  43.  
  44. // ******************************************************************
  45. //
  46. //                PARTICLE EXPRESSION EDITOR PROCEDURES
  47. //
  48. // ******************************************************************
  49.  
  50.  
  51. //  ================ EEisParticle ================
  52. //
  53. //  SYNOPSIS
  54. //      Return whether the object is a particle shape
  55. //
  56. global proc int EEisParticle(string $nodeName)
  57. {
  58.     if (!`isTrue "DynamicsUIExists"`)
  59.         return 0;
  60.  
  61.     string $particles[] = `ls -type particle`;
  62.     int $i;
  63.     for ($i = 0; $i < size($particles); $i++)
  64.     {
  65.         if ($nodeName == $particles[$i])
  66.             return 1;
  67.     }
  68.     return 0;
  69.  
  70. }    // EEisParticle
  71.  
  72.  
  73. //  ================ EEisDynExpression ================
  74. //
  75. //  SYNOPSIS
  76. //      Return whether the particle attribute has an expression or
  77. //        a dynExpression
  78. //
  79. global proc int EEisDynExpression(string $objAttrName)
  80. {
  81.     // If the attribute is connected to a TdnExpression node, it is
  82.     // not a dynExpression.
  83.     //
  84.     string $exprName[] =
  85.     `listConnections -s true -d false -t "expression"  -scn true  $objAttrName`;
  86.  
  87.     if (size($exprName))
  88.         return 0;
  89.     else
  90.         return 1;
  91.  
  92. }    // EEisDynExpression
  93.  
  94.  
  95. //  ================ EEisValidDynAttr ================
  96. //
  97. //  SYNOPSIS
  98. //      Return whether the particle attribute is one that's valid
  99. //        to show in the editor.
  100. //
  101. global proc int EEisValidDynAttr(string $attribute)
  102. {
  103.     int $isValid = 0;
  104.  
  105.     if ($attribute != "input" && $attribute != "output" &&
  106.         $attribute != "age" && $attribute != "particleId")
  107.     {
  108.         string $testMatch;
  109.         $testMatch = match("PP0", $attribute);
  110.         if (size($testMatch))
  111.             return 0;
  112.         
  113.         $testMatch = match("PPCache", $attribute);
  114.         if (size($testMatch))
  115.             return 0;
  116.  
  117.         // We can't do match for a word that has a bracked in it;
  118.         // it doesn't work in MEL.  But this does.
  119.         //
  120.         string $buffer[];
  121.         tokenize($attribute, "[", $buffer);
  122.         if ($buffer[0] == "output" && size($buffer) > 1)
  123.             return 0;
  124.  
  125.         $isValid = 1;
  126.     }
  127.  
  128.     return $isValid;
  129.  
  130. }    // EEisValidDynAttr
  131.  
  132.  
  133. //  ================ EEgetParticleExpression ================
  134. //
  135. //  SYNOPSIS
  136. //      Get and return the particle expression for nodeName
  137. //
  138. global proc string EEgetParticleExpression(string $nodeName, string $attrName)
  139. {
  140.     global int $EEisRuntime;
  141.     string $particleExpr;
  142.  
  143.     if ("" != $nodeName) {
  144.         // If an attrName has been sent in, an attribute is selected, so see
  145.         // first if it is connected to a TdnExpression node, and get that
  146.         // expression.  Otherwise, get a dynExpression if there is one.
  147.         //
  148.         if (size($attrName))
  149.         {
  150.             string $objAttrName = $nodeName + "." + $attrName;
  151.             string $exprName[] =
  152.                 `listConnections -s true -d false -t "expression"  -scn true $objAttrName`;
  153.             if (size($exprName))
  154.                 $particleExpr  = `expression -q -s $exprName[0]`;
  155.         }
  156.  
  157.         if (size($particleExpr) == 0) {
  158.             if ($EEisRuntime) {
  159.                 $particleExpr = `dynExpression -q -r $nodeName`;
  160.             } else {
  161.                 $particleExpr = `dynExpression -q -c $nodeName`;
  162.             }
  163.         }
  164.     }
  165.     return $particleExpr;
  166.  
  167. }    // EEgetParticleExpression
  168.  
  169.  
  170. //  ================ EEdisplayParticleExpression ================
  171. //
  172. //  SYNOPSIS
  173. //      Display the expression connected to the current
  174. //      particle or particle attribute, and
  175. //        put the name in the expression name textfield.
  176. //
  177. //
  178. global proc EEdisplayParticleExpression(string $objAttrName,
  179.                                         string $expression)
  180. {
  181.     global int $EEobjIsParticle;
  182.     global int $EEcurrentEditor;
  183.     global int $EEdoLaunchTextEd;
  184.     global int $EEpExpressionInEditor;
  185.     global int $EEexpressionInEditor;
  186.     global string $EEorigExpressionName;
  187.     global string $EEcurrExpressionName;
  188.  
  189.     // Set the data into the editor controls.
  190.     //
  191.     scrollField -e -tx $expression EEmultiText;
  192.  
  193.     string $buffer[];
  194.     tokenize($objAttrName, ".", $buffer);
  195.  
  196.     if ($EEcurrentEditor != 1 && $EEdoLaunchTextEd)
  197.     {
  198.         EElaunchParticleEditor($expression, $buffer[0]);
  199.         scrollField -e -enable false EEmultiText;
  200.     }
  201.     else
  202.     {
  203.         int $index = EEexpressionIsInTextEditor($buffer[0], 1);
  204.  
  205.         if ($index == -1)
  206.         {
  207.             $EEpExpressionInEditor = -1;
  208.             scrollField -e -enable true EEmultiText;
  209.         }
  210.         else
  211.         {
  212.             $EEpExpressionInEditor = $index;
  213.             scrollField -e -enable false EEmultiText;
  214.         }
  215.     }
  216.     $EEexpressionInEditor = -1;
  217.     $EEdoLaunchTextEd = 0;
  218.  
  219.     text -e -enable false EEexprNameLabel;
  220.     EEresetExpressionName($objAttrName);
  221.     
  222.     textField -e -enable false EEexprNameT;
  223.     textFieldGrp -e -tx $objAttrName EEselNameT;
  224.     textFieldGrp -e -tx "" -enable false EEdefNameT;
  225.     
  226.     $EEcurrExpressionName = $objAttrName;
  227.     $EEorigExpressionName = $objAttrName;
  228.  
  229.     EEsetEditMode("Editing Particle Expression");
  230.  
  231. }    // EEdisplayParticleExpression
  232.  
  233.  
  234. //  ================ EEdynExpressionCmd ================
  235. //
  236. //  SYNOPSIS
  237. //      Build the optional command args for the dynExpression command
  238. //
  239. //
  240. global proc string EEdynExpressionCmd( int $isRuntime,
  241.                                         string $expression, string $particleObj)
  242. {
  243.     global int $EEeditedInEditor;
  244.  
  245.     string $cmd;
  246.     string $exprReturn;
  247.  
  248.     $EEeditedInEditor = 1;
  249.     if ($isRuntime)
  250.     {
  251.         $cmd = ("dynExpression -s \""+encodeString($expression)+"\" -r "+$particleObj+";");
  252.         $exprReturn = evalEcho($cmd);
  253.     }
  254.     else
  255.     {
  256.         $cmd = ("dynExpression -s \""+encodeString($expression)+"\" -c "+$particleObj+";");
  257.         $exprReturn = evalEcho($cmd);
  258.     }
  259.  
  260.     return $exprReturn;
  261.     
  262. }    // EEdynExpressionCmd
  263.  
  264.  
  265.  
  266. //  ================ EEapplyParticleExpression ================
  267. //
  268. //  SYNOPSIS
  269. //      Create the expression in the editor and connect it to
  270. //        to the current selected attribute or
  271. //        replace its current expression with the newly edited one.
  272. //
  273. //
  274. global proc EEapplyParticleExpression(string $expression)
  275. {
  276.     global int $EEisRuntime;
  277.     global string $EEcurrExpressionName;
  278.     global string $EEorigExpressionName;
  279.  
  280.     string $particleAttrName, $particleObj, $particleAttr;
  281.     string $exprReturn;
  282.  
  283.     $particleAttrName = `textFieldGrp -q -tx EEselNameT`;
  284.  
  285.     string $buffer[];
  286.     tokenize($particleAttrName, ".", $buffer);
  287.     $particleObj = $buffer[0];
  288.     $particleAttr = $buffer[1];
  289.  
  290.     if (size($particleObj) == 0)
  291.     {
  292.         warning "Expression Editor: no particle object is selected.";
  293.         return;
  294.     }
  295.  
  296.     string $testExpr;
  297.     $testExpr = ("\""+$expression+"\"");
  298.  
  299.     $exprReturn = EEdynExpressionCmd($EEisRuntime, $expression, $particleObj);
  300.  
  301.     if ($exprReturn != "NULL")
  302.         EEsetEditMode("Editing Particle Expression");
  303.  
  304. }    // EEapplyParticleExpression
  305.  
  306.  
  307.  
  308. //  ================ EErestoreParticleExpression ================
  309. //
  310. //  SYNOPSIS
  311. //      Restore the current particle expression to the editor 
  312. //
  313. //
  314. global proc EErestoreParticleExpression()
  315. {
  316.     string $currObjAttrName = `textFieldGrp -q -tx EEselNameT`;
  317.  
  318.     string $buffer[];
  319.     tokenize($currObjAttrName, ".", $buffer);
  320.  
  321.     string $expression = EEgetParticleExpression($buffer[0], $buffer[1]);
  322.  
  323.     scrollField -e -tx $expression EEmultiText;
  324.  
  325. }    // EErestoreParticleExpression
  326.  
  327.  
  328. //  ================ EEparticleListChanged ================
  329. //
  330. //  SYNOPSIS
  331. //     A particle node in the scrolled text list of nodes is selected.
  332. //
  333. global proc EEparticleListChanged(string $nodeName)
  334. {
  335.     global string $EEnodeMode;
  336.     global string $EEcurrSelectedNode;
  337.     global int $EEcurrentEditor;
  338.     global int $EEdoLaunchTextEd;
  339.  
  340.     string $particleExpr;
  341.  
  342.     // Here and below have to take into account that the user may
  343.     // have clicked (esp. double-clicked) on the node that is 
  344.     // currently already in the editor.  In that case, the only
  345.     // thing that needs to be done is launch a text editor, if the
  346.     // the user double-clicked.
  347.     //
  348.     if ($nodeName != $EEcurrSelectedNode)
  349.     {
  350.         if ($EEnodeMode == "object")  
  351.         {
  352.             // Object/attribute mode; user is selecting an object:
  353.     
  354.             // Clear all the controls in the editor, if a new node has
  355.             // been selected, and display the attrs of the new one.
  356.             //
  357.             EEclearAllControls();
  358.             EEresetNodeControls($nodeName);
  359.     
  360.         }
  361.         else
  362.         {
  363.             // Open the rules form.
  364.             //
  365.             EEswitchRulesForm(1);
  366.         }
  367.         // Display the particle expression if there is one.  If the
  368.         // user has double-clicked, it will be put in a text editor 
  369.         // in the display procedure.
  370.         //
  371.         $particleExpr = EEgetParticleExpression($nodeName, "");
  372.         if (size($particleExpr) == 0)
  373.             EEdisplayNoExpression($nodeName);
  374.         else
  375.             EEdisplayParticleExpression($nodeName, $particleExpr);
  376.     }
  377.     else
  378.     {
  379.         // User has re-selected the previous node, so just launch a
  380.         // text editor if the user double-clicked.
  381.         //
  382.         if ( $EEcurrentEditor != 1 && $EEdoLaunchTextEd)
  383.         {
  384.             string $particleExpr = EEgetParticleExpression($nodeName, "");
  385.  
  386.             EElaunchParticleEditor($particleExpr, $nodeName);
  387.             scrollField -e -enable false EEmultiText;
  388.         }
  389.     }
  390.  
  391. }    // EEparticleListChanged
  392.  
  393.  
  394. //  ================ EEonlyLaunchParticleEditor ================
  395. //
  396. //  SYNOPSIS
  397. //      Don't create and show the expression editor window; just
  398. //        launch a text editor.
  399. //
  400. global proc EEonlyLaunchParticleEditor(string $nodeName, string $attrName)
  401. {
  402.  
  403.     // Find the expression, if there is one that this node.attr is
  404.     // connected to.
  405.     //
  406.     $particleExpr = EEgetParticleExpression($nodeName, $attrName);
  407.  
  408.     EElaunchParticleEditor($particleExpr, $nodeName);
  409.  
  410. }    // EEonlyLaunchParticleEditor
  411.  
  412.  
  413.